<script setup lang="ts">

import {EditPen, SwitchButton, User} from "@element-plus/icons-vue";

import {ref} from 'vue'
import {logoutService} from "@/api/server/admin.ts";
import {removeServerToken} from "@/utils/token.ts";
import router from "@/router";

const logoutDialogVisible = ref(false)

async function logout() {
  logoutDialogVisible.value = false
  try {
    await logoutService()
    removeServerToken()
    await router.push("/server/login");
  } catch (error) {
    console.log(error)
  }
}

</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <div class="admin-name">管理员</div>

        <el-tooltip content="退出登录" placement="bottom">
          <el-button :icon="SwitchButton" plain @click="logoutDialogVisible = true"/>
        </el-tooltip>
        <el-dialog
            v-model="logoutDialogVisible"
            width="300"
        >
          <span>你确定要退出登录吗？</span>
          <template #footer>
            <div class="dialog-footer">
              <el-button @click="logoutDialogVisible = false">取消</el-button>
              <el-button type="primary" @click="logout()">
                确定
              </el-button>
            </div>
          </template>
        </el-dialog>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
              default-active="/server/home/problem"
              router
              class="el-menu-vertical-demo"
          >
            <el-menu-item index="/server/home/problem-manage">
              <el-icon>
                <EditPen/>
              </el-icon>
              <span>题目管理</span>
            </el-menu-item>

<!--            <el-menu-item index="/server/home/user-manage">-->
<!--              <el-icon>-->
<!--                <User/>-->
<!--              </el-icon>-->
<!--              <span>用户管理</span>-->
<!--            </el-menu-item>-->
          </el-menu>
        </el-aside>
        <el-main>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped lang="scss">
.common-layout {
  :deep(.el-container) {
    height: 100vh;

    .el-header {
      background-color: #F8F9FA;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      margin-right: 50px;

      .admin-name {
        margin-right: 20px;
      }

      .el-button {
        border: 0;
      }
      .el-overlay-dialog {
        top: 25%;
      }
    }

    .el-container {
      .el-aside {
        .el-menu {
          border: 0;
        }

        border-right: 1px solid #dcdfe6;
      }

      .el-main {
        padding: 0;
        min-height: 730px;
      }
    }
  }
}
</style>